<template>
  <div class="friend-card">
    <!-- 第一行：主要信息 -->
    <div class="info-row">
      <img :src="info.friend_info.head_image || '/public/yonghu.png'" alt="头像" class="avatar">
      
      <div class="main-info">
        <div class="name-line">
          <span class="username">{{ info.friend_info.username || "匿名"}}</span>
          <span class="meta">
            <span class="age">{{ info.friend_info.age }}岁</span>
            <span class="sex">{{ info.friend_info.sex }}</span>
          </span>
        </div>
        
        <div class="secondary-info">
          <span class="email">{{ info.friend_info.email }}</span>
          <span class="intro">{{ info.friend_info.introduction || '暂无简介' }}</span>
        </div>
      </div>
    </div>
    
    <!-- 第二行：交互按钮 -->
    <div class="action-row">
      <button v-for="(i,index) in funccollections" :key="index"  class="action-btn chat-btn" 
      @click="i.onclick">
        {{i.name}}
      </button>
    </div>
  </div>
</template>

<script setup>
import { defineProps, inject, onMounted } from "vue"
import { delete_friends } from "@/api/chat/room"
const chat = inject('chat')()
const room_stream = inject('room_stream')
const room_cache=inject('cacahe_room_info')
const props = defineProps({
  info: {
    type: Object,
    required: true
  }
})
const startChat = () => {
  chat.value.set_current_chat({room_id:props.info.room_info.room_id,type:props.info.room_info.type})
  chat.value.add_current_chat_list(props.info.room_info.room_id, props.info)
}

const showMore = () => {
  // 展开/更多逻辑
  chat.value.set_current_show_info_room_info(
    {
      room_id: props.info.room_info.room_id,
      type: props.info.room_info.type
    }
  )
}
const funccollections = [

  {

    'name': '发送消息',
    'icon':'',
     onclick: startChat,
  },
  {
    'name': '删除好友',
    'icon':'',
    onclick: async () => { 
      const judge = await delete_friends(chat.value.get_user_info().id, props?.info?.friend_info?.id)
      if (judge == 200) { 
        chat.value.pop_room_unrend_lastmessage_item(props?.info?.room_info?.room_id)
        chat.value.pop_current_chat_list_item(props?.info?.room_info?.room_id);
        chat.value.pop_frined_list_item(props?.info?.room_info?.room_id);
        await room_stream.deleteData(props?.info?.room_info?.room_id);
        await room_cache.deleteData(props?.info?.room_info?.room_id);
      }
    },
  }, {
    'name': '更多',
    'icon':'',
     onclick: showMore,
  }
]

</script>

<style scoped>
.friend-card {
  width: 150%;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  padding: 12px;
  font-family: 'Arial', sans-serif;
}

.info-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid #f0f0f0;
}

.main-info {
  flex: 1;
  min-width: 0;
}

.name-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 4px;
}

.username {
  font-weight: bold;
  font-size: 15px;
  color: #333;
}

.meta {
  display: flex;
  gap: 8px;
  font-size: 13px;
  color: #888;
}

.secondary-info {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 13px;
  color: #666;
 
}

.secondary-info > span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.email {
  color: #1890ff;
}

.action-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px dashed #eee;
}

.action-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 12px;
  border: none;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.chat-btn {
  background-color: #e6f7ff;
  color: #1890ff;
}

.chat-btn:hover {
  background-color: #bae7ff;
}

.more-btn {
  background-color: #f5f5f5;
  color: #666;
}

.more-btn:hover {
  background-color: #e8e8e8;
}

.icon {
  font-size: 14px;
}

</style>